package com.aktiehuis.bean;

import java.io.Serializable;

import javax.ejb.EJB;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.aktiehuis.main.Klant;
import com.aktiehuis.main.Winkel;
import com.aktiehuis.main.Winkelmand;

@Table(name="klanten")
@Entity
public class KlantBean implements Klant, Serializable {
	private static final long serialVersionUID = -5325825510768570553L;
	@Id @GeneratedValue public int id = 0;
	public String naam = null;
	@EJB @Transient public Winkel winkel = null;
	@EJB @Transient public Winkelmand winkelmand = null;
	
	public KlantBean() {
		id = 0;
		naam = null;
		winkel = null;
		winkelmand = null;
	}
	
	public KlantBean( int newId, String newNaam ) {
		id = newId;
		naam = newNaam;
		winkel = null;
		winkelmand = new WinkelmandBean();
	}
	
	public int getId() {
		return id;
	}
	
	public String getNaam() {
		return naam;
	}
	
	public Winkelmand getWinkelmand() {
		return winkelmand;
	}
	
	public void enter( Winkel newWinkel ) {
		if( winkel == null ) {
			winkel = newWinkel;
			
			winkel.enter( this );
		}
	}
	
	public void verlaat() {
		if( winkel != null ) {
			winkel.verlaat( this );
			
			winkel = null;
		}
	}
}
